package com.zyy.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

/**
 * @Description: 登录管理
 * @Author: zyy
 * @Date: 2022/08/09 15:58
 */
@Controller
public class LoginController {

    @RequestMapping("/user/login")
    public String login(@RequestParam("username") String userName,
                        @RequestParam("password") String password,
                        Model model,
                        HttpSession session) {
        if ("admin".equals(userName) && "123456".equals(password)) {
            session.setAttribute("userInfo", session);
            return "redirect:/main.html";
        }
        model.addAttribute("msg", "用户名或者密码有误");
        return "index";
    }

    @RequestMapping("/user/logout")
    public String logout(HttpSession session) {
        session.removeAttribute("userInfo");
        return "redirect:/index.html";
    }

}
